import { Component, createSignal } from "solid-js";

import { WorkList } from "@/components/workList/index";
import { transPlans, useWorkPlanStore } from "./components/workList/store";

const App: Component = () => {
  let [previewUrl, setPreviewUrl] = createSignal(
    localStorage.getItem("previewUrl") || ""
  );
  let { workStore } = useWorkPlanStore();
  let thisWeekRef: HTMLElement | undefined;
  let toText = () => {
    console.clear();
    let txt = `本周工作完成情况
${transPlans(workStore["thisWeek"], " ").join("\r\n")}
预览地址
    ${previewUrl() || "暂无"}
下周工作计划
${transPlans(workStore["nextWeek"], " ").join("\r\n")}
    `;
    console.log(txt);
    navigator.clipboard.writeText(txt);
  };

  return (
    <div>
      <h1>工作周报</h1>
      <h2>本周工作完成情况</h2>
      <WorkList ref={thisWeekRef} id="thisWeek" />
      <h2>预览地址</h2>
      <input
        placeholder="请输入预览地址"
        value={previewUrl()}
        onchange={e => {
          setPreviewUrl(e.currentTarget.value);
          localStorage.setItem("previewUrl", previewUrl());
        }}
      ></input>
      <h2>下周工作计划</h2>
      <WorkList id="nextWeek" />
      <button type="button" onClick={toText}>
        复制到剪贴板
      </button>
    </div>
  );
};

export default App;
